import axios from 'axios';
import queryString from 'qs';
import _ from 'lodash';
import { downloadFile } from '@util/download-file';

export const getDictsList = params => {
  return axios.get(
    `/api/task/dict/list?${queryString.stringify(_.pickBy(params, Boolean), {
      arrayFormat: 'repeat'
    })}`
  );
};

export const addDict = body => {
  return axios.post('/api/task/dict/add', body);
};

export const deleteDicts = body => {
  return axios.post('/api/task/dict/delete', body);
};

export const downloadDict = params => {
  return downloadFile('get', `/api/task/dict/download?${queryString.stringify(params)}`);
};

export const getAllDicts = () => {
  return axios.get('/api/task/dict/all');
};
